package JavaTest.sectionTest.Test3;

public class Test1 {
    public static void main(String[] args) {
        Person person0 = new Person(18,"a");
        Person person1 = new Person(20,"b");
        Person person2 = new Person(17,"c");
        Person[] people = new Person[3];
        people[0] = person0;people[1] = person1;people[2] = person2;
        Test1 test03 = new Test1();
        test03.bubbleSort(people);
        for (Person temp :
                people) {
            System.out.println(temp.age+" "+temp.name);
        }
    }

    public  void bubbleSort(Person[] people){
        int length = people.length;
        for (int i = 0; i < length; i++) {
            for (int j = 0; j < length-1; j++) {
                if (people[j].age > people[j+1].age){
                    Person temp = people[j];
                    people[j] = people[j+1];
                    people[j+1] = temp;
                }
            }
        }
    }
}

class Person{
    public int age;
    public String name;

    public Person(int age, String name) {
        this.age = age;
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
